winsafe\dshow\com_interfaces/
imediaseeking.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::dshow::vts::*;
6use crate::kernel::privs::*;
7use crate::ole::privs::*;
8use crate::prelude::*;
9
10com_interface! { IMediaSeeking: "36b73880-c2c8-11cf-8b46-00805f6cef60";
11	/// [`IMediaSeeking`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nn-strmif-imediaseeking)
12	/// COM interface.
13	///
14	/// Automatically calls
15	/// [`IUnknown::Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
16	/// when the object goes out of scope.
17	///
18	/// # Examples
19	///
20	/// ```no_run
21	/// use winsafe::{self as w, prelude::*};
22	///
23	/// let graph_builder: w::IGraphBuilder; // initialized somewhere
24	/// # let graph_builder = unsafe { w::IGraphBuilder::null() };
25	///
26	/// let media_seeking = graph_builder
27	///     .QueryInterface::<w::IMediaSeeking>()?;
28	/// # w::HrResult::Ok(())
29	/// ```
30}
31
32impl dshow_IMediaSeeking for IMediaSeeking {}
33
34/// This trait is enabled with the `dshow` feature, and provides methods for
35/// [`IMediaSeeking`](crate::IMediaSeeking).
36///
37/// Prefer importing this trait through the prelude:
38///
39/// ```no_run
40/// use winsafe::prelude::*;
41/// ```
42pub trait dshow_IMediaSeeking: ole_IUnknown {
43	/// [`IMediaSeeking::ConvertTimeFormat`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-converttimeformat)
44	/// method.
45	#[must_use]
46	fn ConvertTimeFormat(
47		&self,
48		target_format: &co::TIME_FORMAT,
49		source: i64,
50		source_format: &co::TIME_FORMAT,
51	) -> HrResult<i64> {
52		let mut target = 0i64;
53		ok_to_hrresult(unsafe {
54			(vt::<IMediaSeekingVT>(self).ConvertTimeFormat)(
55				self.ptr(),
56				&mut target,
57				pcvoid(target_format),
58				source,
59				pcvoid(source_format),
60			)
61		})
62		.map(|_| target)
63	}
64
65	/// [`IMediaSeeking::GetAvailable`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-getavailable)
66	/// method.
67	///
68	/// Returns earliest and latest times for efficient seeking.
69	#[must_use]
70	fn GetAvailable(&self) -> HrResult<(i64, i64)> {
71		let (mut early, mut late) = (0i64, 0i64);
72		ok_to_hrresult(unsafe {
73			(vt::<IMediaSeekingVT>(self).GetPositions)(self.ptr(), &mut early, &mut late)
74		})
75		.map(|_| (early, late))
76	}
77
78	/// [`IMediaSeeking::GetCurrentPosition method`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-getcurrentposition)
79	/// method.
80	#[must_use]
81	fn GetCurrentPosition(&self) -> HrResult<i64> {
82		let mut pos = 0i64;
83		ok_to_hrresult(unsafe {
84			(vt::<IMediaSeekingVT>(self).GetCurrentPosition)(self.ptr(), &mut pos)
85		})
86		.map(|_| pos)
87	}
88
89	/// [`IMediaSeeking::GetDuration`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-getduration)
90	/// method.
91	#[must_use]
92	fn GetDuration(&self) -> HrResult<i64> {
93		let mut duration = 0i64;
94		ok_to_hrresult(unsafe {
95			(vt::<IMediaSeekingVT>(self).GetDuration)(self.ptr(), &mut duration)
96		})
97		.map(|_| duration)
98	}
99
100	/// [`IMediaSeeking::GetPositions`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-getpositions)
101	/// method.
102	///
103	/// Returns current and stop positions.
104	#[must_use]
105	fn GetPositions(&self) -> HrResult<(i64, i64)> {
106		let (mut current, mut stop) = (0i64, 0i64);
107		ok_to_hrresult(unsafe {
108			(vt::<IMediaSeekingVT>(self).GetPositions)(self.ptr(), &mut current, &mut stop)
109		})
110		.map(|_| (current, stop))
111	}
112
113	/// [`IMediaSeeking::GetPreroll`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-getpreroll)
114	/// method.
115	#[must_use]
116	fn GetPreroll(&self) -> HrResult<i64> {
117		let mut preroll = 0i64;
118		ok_to_hrresult(unsafe {
119			(vt::<IMediaSeekingVT>(self).GetPreroll)(self.ptr(), &mut preroll)
120		})
121		.map(|_| preroll)
122	}
123
124	/// [`IMediaSeeking::GetRate`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-getrate)
125	/// method.
126	#[must_use]
127	fn GetRate(&self) -> HrResult<f64> {
128		let mut rate = f64::default();
129		ok_to_hrresult(unsafe { (vt::<IMediaSeekingVT>(self).GetRate)(self.ptr(), &mut rate) })
130			.map(|_| rate)
131	}
132
133	/// [`IMediaSeeking::GetStopPosition`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-getstopposition)
134	/// method.
135	#[must_use]
136	fn GetStopPosition(&self) -> HrResult<i64> {
137		let mut pos = 0i64;
138		ok_to_hrresult(unsafe {
139			(vt::<IMediaSeekingVT>(self).GetStopPosition)(self.ptr(), &mut pos)
140		})
141		.map(|_| pos)
142	}
143
144	/// [`IMediaSeeking::GetTimeFormat`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-gettimeformat)
145	/// method.
146	#[must_use]
147	fn GetTimeFormat(&self) -> HrResult<co::TIME_FORMAT> {
148		let mut time_guid = co::TIME_FORMAT::NONE;
149		ok_to_hrresult(unsafe {
150			(vt::<IMediaSeekingVT>(self).GetTimeFormat)(self.ptr(), pvoid(&mut time_guid))
151		})
152		.map(|_| time_guid)
153	}
154
155	/// [`IMediaSeeking::SetPositions`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-setpositions)
156	/// method.
157	fn SetPositions(
158		&self,
159		current: i64,
160		current_flags: co::SEEKING_FLAGS,
161		stop: i64,
162		stop_flags: co::SEEKING_FLAGS,
163	) -> HrResult<()> {
164		let (mut current, mut stop) = (current, stop);
165		match unsafe {
166			co::HRESULT::from_raw((vt::<IMediaSeekingVT>(self).SetPositions)(
167				self.ptr(),
168				&mut current,
169				current_flags.raw(),
170				&mut stop,
171				stop_flags.raw(),
172			) as _)
173		} {
174			co::HRESULT::S_OK | co::HRESULT::S_FALSE => Ok(()),
175			hr => Err(hr),
176		}
177	}
178
179	/// [`IMediaSeeking::SetRate`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-setrate)
180	/// method.
181	fn SetRate(&self, rate: f64) -> HrResult<()> {
182		ok_to_hrresult(unsafe { (vt::<IMediaSeekingVT>(self).SetRate)(self.ptr(), rate) })
183	}
184
185	/// [`IMediaSeeking::SetTimeFormat`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-imediaseeking-settimeformat)
186	/// method.
187	fn SetTimeFormat(&self, format: &co::TIME_FORMAT) -> HrResult<()> {
188		ok_to_hrresult(unsafe {
189			(vt::<IMediaSeekingVT>(self).SetTimeFormat)(self.ptr(), pcvoid(format))
190		})
191	}
192}